import { WeaSearchGroup,WeaFormItem } from 'ecCom';
import { Button,Tooltip,Icon } from 'antd';
import { inject, observer} from 'mobx-react';
import {WeaSwitch} from 'comsMobx';
import * as mobx from 'mobx'


@observer
class Condition extends React.Component{

    render(){
        const { condition,form,showSearchAd} = this.props.listStore;	
        const { onEnterSearch } = this.props;	       
        let conditions = [];
        let formParams = {};
        let isFormInit = form.isFormInit;
        conditions = mobx.toJS(condition);
        formParams = form.getFormParams();        

        let group = [];
        isFormInit && conditions.map(c =>{
            let items = [];
            c.items.map((fields, idx) => {  
                items.push({
                    com:(<WeaFormItem
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                            <WeaSwitch fieldConfig={fields} form={form}  />        
                        </WeaFormItem>),
                    colSpan:1,
                })
            });

            group.push(<WeaSearchGroup needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}  onEnterSearch={onEnterSearch}/>)
        });

        return <div>{group}</div>;
    }
 
}

const getAdButtons = (listStore) => {
	const {doSearch,setShowSearchAd,clearFormFields} = listStore;
	return [
		(<Button type="primary" onClick={()=>{doSearch();setShowSearchAd(false);}}>搜索</Button>),
		(<Button type="ghost" onClick={()=>{clearFormFields();}}>重置</Button>),
		(<Button type="ghost" onClick={()=>{setShowSearchAd(false)}}>取消</Button>)
	];
}

export {Condition,getAdButtons}
